<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
		canvas{border: 1px solid #333;}
	</style>
</head>
<body>
	<canvas width="600" height="400"></canvas>
	<script type="text/javascript">
		let canvas=document.querySelector("canvas")
		let ctx=canvas.getContext("2d")
		let R=200;


		//移动坐标系到画布中间
		ctx.translate(300,200)


		function staticClock(){

		//绘制大圆
		ctx.beginPath()
		ctx.strokeStyle="#000"
		ctx.arc(0,0,R,0,Math.PI*2,false)
		ctx.lineWidth=5;
		ctx.stroke()



		/**绘制分针刻度辐射线**/
		ctx.beginPath()
		ctx.lineWidth=2;
		// ctx.strokeStyle="black;"


		for(let i=0;i<60;i++){
			ctx.save()
			ctx.rotate(i*6*Math.PI/180)
				ctx.moveTo(0,0)
				ctx.lineTo(0,-R)
				ctx.stroke()
			ctx.restore()
		}

		//覆盖白色圆
		ctx.beginPath()
		ctx.arc(0,0,R-10,0,Math.PI*2,false)
		ctx.fillStyle="white";
		ctx.fill()



		/*时针刻度辐射线*/
		ctx.beginPath()
		ctx.lineWidth=5

		for(let i=0;i<12;i++){
			ctx.save()
			ctx.rotate(i*30*Math.PI/180)
				ctx.moveTo(0,0)
				ctx.lineTo(0,-R)
				ctx.stroke()
			ctx.restore()
		}

		//覆盖时针刻度线
		ctx.beginPath()
		ctx.arc(0,0,R-20,0,Math.PI*2,false)
		ctx.fillStyle="white"
		ctx.fill()

		//求III的坐标
		let r=R-40;
		let arr=["III","IV","V","VI","VII","VIII","IX","X","XI","XII","I","II"]
		for(let i=0;i<12;i++){
			var x=r*Math.cos(i*30*Math.PI/180)
			var y=r*Math.sin(i*30*Math.PI/180)
			// console.log(x,y)
			ctx.font="20px Arial";
			ctx.fillStyle="black"
			ctx.textAlign="center"
			ctx.textBaseline="middle"
			ctx.fillText(arr[i],x,y)
		}
			//绘制logo
		ctx.beginPath()
		ctx.textAlign="center"
		ctx.fillText("Daniel Wellington",0,-R/3)


	}

		//静止的表盘
		staticClock()

	
		//绘制红点
		function dot(){
			
			ctx.beginPath()
			ctx.arc(0,0,5,0,Math.PI*2,false)
			ctx.fillStyle="red"
			ctx.fill()
		}
	



		// 绘制秒针
		function secondHandle(){
			//绘制新的秒针
			let second = new Date().getSeconds()
			ctx.beginPath()
			ctx.lineWidth=2;
			ctx.strokeStyle="blue"
			ctx.save()
			ctx.rotate(second*6*Math.PI/180)

				ctx.moveTo(0,50)
				ctx.lineTo(0,-R+35)
				ctx.stroke()

			ctx.restore()
		}

		//绘制分针
		function minuteHandle(){

			ctx.beginPath()
			ctx.strokeStyle="black"
			ctx.lineWidth=4;
			ctx.save()
			let minute=new Date().getMinutes()
		
			ctx.rotate(minute*6*Math.PI/180)
				ctx.moveTo(0,30)
				ctx.lineTo(0,-R+60)

				ctx.stroke()

			ctx.restore()
		}


		//绘制时针
		function hourHandle(){
			ctx.beginPath()
			ctx.strokeStyle="#000";
			ctx.lineWidth=6
			ctx.save()
			let hour=new Date().getHours()
			let minute=new Date().getMinutes()
			ctx.rotate((hour*30+minute*0.5)*Math.PI/180)
				ctx.moveTo(0,30)
				ctx.lineTo(0,-R+80)
				ctx.stroke()

			ctx.restore()
		}


		//绘制秒针
		secondHandle()


		//绘制分针
		minuteHandle()

		//绘制时针
		hourHandle()


		//绘制红点
		dot()

		
		setInterval(()=>{
			//清除以前的痕迹
			ctx.clearRect(-R,-R,2*R,2*R)

			//绘制表盘
			staticClock()

			//绘制秒针
			secondHandle()

			//绘制时针
			hourHandle()

			//绘制分针
			minuteHandle()

			//绘制红点
			dot()

		},1000)


		
	



	</script>
</body>
</html>